package com.csweimei.rentmanagementtreasure.enterprise.act;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;
import android.view.View;

import com.chad.library.BR;
import com.csweimei.rentmanagementtreasure.R;
import com.csweimei.rentmanagementtreasure.base.AppConfig;
import com.csweimei.rentmanagementtreasure.base.AppViewModelFactory;
import com.csweimei.rentmanagementtreasure.databinding.ActivityStaffDetailBinding;
import com.csweimei.rentmanagementtreasure.enterprise.viewModel.StaffDetailVM;
import com.google.android.material.tabs.TabLayout;

import me.goldze.mvvmhabit.base.BaseActivity;

public class StaffDetailActivity extends BaseActivity<ActivityStaffDetailBinding, StaffDetailVM> {


    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_staff_detail;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }


    String userID;
    String entId;
    @Override
    public void initParam() {
        super.initParam();
        userID = getIntent().getStringExtra(AppConfig.BUNDLE_KEY);
        entId = getIntent().getStringExtra(AppConfig.BUNDLE_KEY2);
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.setActivity(this);
        viewModel.userid.set(userID);
        viewModel.companyID.set(entId);

        binding.tab.addTab(binding.tab.newTab().setText("房源"));
        binding.tab.addTab(binding.tab.newTab().setText("客户"));
        binding.tab.addTab(binding.tab.newTab().setText("日报"));
        binding.tab.addTab(binding.tab.newTab().setText("跟进"));

        binding.tab.getTabAt(0).select();
        viewModel.brokerHousingData();
        viewModel.showHouse.set(View.VISIBLE);

        binding.tab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewModel.recyComm();
                switch (tab.getPosition()){
                    case 0:
                        viewModel.brokerHousingData();
                        viewModel.showHouse.set(View.VISIBLE);
                        break;
                    case 1:
                        viewModel.brokerCustomData();
                        viewModel.showCustomer.set(View.VISIBLE);
                        break;
                    case 2:
                        viewModel.brokerDailyData();
                        viewModel.showDaily.set(View.VISIBLE);
                        break;
                    case 3:
                        viewModel.brokerFollowupData();
                        viewModel.showFollow.set(View.VISIBLE);
                        break;
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @Override
    public StaffDetailVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this,factory).get(StaffDetailVM.class);
    }
}